Help:Parser functions
Parser functions used in templates with parameters #if function The basic premise is, the function checks to see if a variable is not empty: If (variable) IS NOT EMPTY then TRUE else FALSE Named parameters If the parameters are named then the if function takes the following form: } | true | false }} Seems, innocuous enough, but if used in a template then the very fact that you are using a variable will cause there to be something that exists in the template unless you swap it with an incoming parameter value (a non null value or null value) i.e., the variable is always there even though the parameter in the calling function may not be there. This means that all it is good for is checking whether the variable is empty / null: |x=3 => TRUE |x= => FALSE => } | true | false }} TRUE |y=cheese => } | true | false }} TRUE The #if function can be made useful within the process of calling templates by using the "default value" operator |. This operator is a feature of calling templates; the | has different meanings outside of this context. Within the context of calling templates, it will work thusly: if there is nothing passed in to the variable before the | operator then whatever is after the | operator is "transcluded" (overwritten) in place of the } code. If there is something in the parameter passed to the variable before the | operator it will use that. It will then go on to evaluate whatever has been "transcluded". Examples If x=3, then passing it to a template with the following code }, will transclude it to just 3, which will evaluate as 3. If x=, then passing it to a template with the following code }, will see that x is empty and thus transclude it with the null after the | which evaluates as just null. If x is not among the parameters passed in to the template, then the following code }, will see that x is empty so transclude the null again which evaluates as just null. If x=, then passing it to a template with the following code }, will see that x is empty and thus transclude it with "an arbitrary value used for this example" which will leave the template to evaluate the string. Use in templates } | true | false }} In the above code example ,the first thing that happens is that any parameter that exists, has its value passed in and is "transcluded" with x. If x does not exist then it will "transclude" the value after the |, which in this case is null. The null value now "transcludes" the variable. The #if function will now only pass TRUE if there is a parameter value other than null, passed to the variable: If x=3 => } | true | false }} => TRUE If x= => } | true | false }} => FALSE If => } | true | false }} => FALSE If y=cheese => } | true | false }} => FALSE Practical use of the #if function You can hide table rows which contain empty parameters by using: } | - } }} The above code produces the following output only if varInput is defined and has a value. |- | varInput Outside of the context of template variables/parameters, the | operator is a variable seperator or "OR" operator. So in the above example; the first | after "varInput" belongs to the template variable and is the "default" operator, the second | is a seperator for the #if statement (a third seperator could have been used if you need different output based on excluding the "varInput" parameter, but in this case it will output nothing). The is used in the above example instead of | as the "Parser function extension" would otherwise confuse it with the parameter seperators of the #if function. is a template (which can be seen at Template:!) which transcludes (adds in) | into the code after the parser function has been validated. What is |- ? I'm not sure how this works as I can't find any documentation on it but this operator will allow you to test whether a parameter was specified in a template call: } | } | v was specified (and may be empty) | v was not specified }} Testing results: If V=5 THEN true If v= THEN true If v=piece THEN true If no variable THEN false If u=5 THEN false Logical functions Details can be found for logical functions on the Mediawiki site *#expr **Rounding *#if *#ifeq *#iferror *#ifexpr *#ifexist *#rel2abs *#switch **Default **Grouping results **Comparison behaviour **Raw equal signs *#time *#timel *#titleparts String functions Details can be found on the Mediawiki site string functions 1 String operations *#len: *#pos: *#rpos: *#sub: *#pad: *#replace: *#explode: *#urlencode: and #urldecode: 2 Limits * $wgStringFunctionsLimitSearch * $wgStringFunctionsLimitReplace * $wgStringFunctionsLimitPad Template Sandbox The following template has been set up to test things like parser functions Template:ParserFunctions. See also * * Parser functions on Mediawiki * Regular Expressions on wikipedia * Regular expression on Perl.org * Regular expressions on PHP.net * Regular expressions on mkssoftware __NOEDITSECTION__